<?php

namespace app\demo\controller;

use my\JRedis;

class Redis extends Base
{

    public function index()
    {
//        $res = JRedis::client()->zRevRangeByScore("rank",time(),time()-600,['withscores'=>true,'limit'=>[0,3]]);
        $res = JRedis::client()->zRevRangeByScore("equip_online_set",'+inf',0,['withscores'=>true,'limit'=>[0,3]]);
        pp($res);
        var_dump($res);
    }

    // 判断设备是否在线, 10分钟内有数据就算在线, 没有则算离线
    public function isOnline() {
        $res = JRedis::client()->zRevRangeByScore("equip_online_set",time(),time()-600,['withscores'=>true,'limit'=>[0,10000]]);
        return successReturn($res);
    }

    // 获取最新的20条数据, list存储

    public function latestData() {
        for($i=1;$i<=10;$i++) {
            $res = JRedis::client()->zAdd('rank',time(),'bms00' . $i);
            usleep(1000000);
            var_dump($res);
        }
//        $res = JRedis::client()->zAdd('rank',time(),'bms004');
//        var_dump($res);
    }

    private function hset()
    {
//        $res = $redis::hGetAll('hash');
//        $redis::hSet("user1","id",1992);
//        $redis::hSet("user1","name","姜海蕤");
//        $redis::hSet("user1","age",32);
//        $redis::hSet("user1","sex",1);
        $time = time();
        $res = JRedis::set('log' . $time, $time);
        pp(date('Y-m-d H:i:s'));
        pp($res);
    }


}
